package ecom.login;

/**
 *
 * @author Miko
 */


import util.Util;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;

public class LoginAction extends ActionSupport implements SessionAware {

    private String login, pass;
    private Map<String, Object> session;

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    @Override
    public void validate() {
        if (login == null || login.equals("")) {
            addFieldError("login", "Login attendu");
        }
        if (pass == null || pass.equals("")) {
            addFieldError("pass", "Mot de passe attendu");
        }
    }

    @Override
    public String execute() {
// gestion du password à améliorer :)
        if (login.equals(pass)) {
            this.session.put(Util.LOGINATTRIBUTE, login);
            return SUCCESS;
        } else {
            return LOGIN;
        }
    }

    public void setSession(Map<String, Object> session) {
        this.session = session;
    }
}

